import Vue from 'vue'
import Vuex from 'vuex'
import {getdata} from '../api'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[],
    item:{},
  },
  mutations: {
    // 渲染列表
    SET_LIST(state,payload){
      state.list=payload
     
    },
    // 编辑功能
    SET_DETAIL(state,payload){
      //  console.log(payload)
    let o=state.list.find(item=>item.id===payload.id)
    state.list.id=o.id,
    state.list.name=o.name,
    state.list.time=o.time,
    state.list.time1=o.time1
   
    state.item=o;
    
    },
    // 删除功能
    SET_FILTER(state,payload){
      //  console.log(payload)
      state.list=state.list.filter(item=>item.id!==payload.id)
    },
    // 添加功能
    SET_ADD(state,payload){
      state.list.push(payload)
    }
  },
  actions: {
   async GET_LIST({commit}){
       const resp=await getdata()
       commit('SET_LIST',resp.data.data)
    }
  },
  modules: {
  }
})
